//
//  HWTextView.m
//  01-黑马微博
//
//  Created by lanou3g on 15/9/21.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "HWTextView.h"

@implementation HWTextView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //不要设置delegate为自己
        //当uitextView文字发生改变时，UItextView会自己发一个UITextViewTextDidChangeNotification
       [HWNotificationCenter addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:self];
    }
    return self;
}

- (void)drawRect:(CGRect)rect{
    //文字属性
//    if (self.text.length > 0) {
//        return;
//    }
    if (self.hasText) {
        return;
    }
    NSMutableDictionary *attrsDict = [NSMutableDictionary dictionary];
    attrsDict[NSFontAttributeName] = self.font;
    attrsDict[NSForegroundColorAttributeName] = self.placeholdrColor;
    //花文字
//    [self.placeholdr drawAtPoint:CGPointMake(5, 8) withAttributes:attrsDict];
    [self.placeholdr drawInRect:CGRectMake(5, 8, rect.size.width - 10, rect.size.height - 8) withAttributes:attrsDict];
}
/**
 *  监听文字改变
 */
- (void)textChange{
    //只有调用这个方法会重新绘制
    [self setNeedsDisplay];
}
- (void)dealloc{
    [HWNotificationCenter removeObserver:self];
}

@end
